package tp.pr5.gui;

import java.awt.Color;

import javax.swing.JButton;

import tp.pr5.PlaceInfo;

public class PlaceCell extends JButton {
	private PlaceInfo place;
	boolean visited;
	boolean active;
	boolean isSpaceShip;
	int xPos;
	int yPos;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * Standard constructor
	 */
	public PlaceCell(){
		super();
		visited = false;
		active = false;
	}
	
	public PlaceCell(int x,int y){
		super();
		visited = false;
		active = false;
		this.xPos=x;
		this.yPos=y;
	}
	
	/**
	 * Gets the place 
	 */
	public PlaceInfo getPlace(){
		return this.place;
	}
	/**
	 * Sets the place 
	 */
	public void setPlace(PlaceInfo pl){
		this.place = pl;
		this.setName(pl.getName());	
		this.isSpaceShip = pl.isSpaceShip();
		//this.setText(this.getName());// TODO quitar cuando este todo listo
	}
	/**
	 * Sets the aspect of the button given its state
	 */
	public void setActive(boolean toggle){
		active = toggle;
		visited = true;
		setText(this.getPlace().getName());
		if (active) setGreen();
		else	    setGray();	
		
	}
	/**
	 * Methods to set the colors
	 */
	public void setGreen(){
		this.setBackground(Color.GREEN);
	}
	public void setGray(){
		this.setBackground(Color.GRAY);
	}
	/**
	 * returns x coord
	 */
	public int getXv(){
		return xPos;
	}
	/**
	 * returns y coord
	 */
	public int getYv(){
		return yPos;
	}
	/**
	 * true if the cell is the active one
	 * @return
	 */
	public boolean isActive(){
		return this.active;
	}
	/**
	 * true if the cell is visited
	 * @return
	 */
	public boolean isVisited(){
		return this.visited;
	}
	/**
	 * sets the visited value
	 * @param toggle
	 */
	public void setVisited(boolean toggle){
		this.visited = toggle;
	}
}
